<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: zhaojia
 * Date: 15-9-16
 * Time: 下午2:32
 */
class News extends CI_Controller{
    public function __construct(){
        parent::__construct();
        $this->load->model('xinwen');

    }

    public function xinwen(){
        $data['news']=$this->xinwen->get_data();
        $this->load->view('admin/news.html',$data);
//        $this->parser->parse('admin/news.html', $data);
    }

    public function add_news(){
        if($_POST){

            $data=$this->input->post();

            $this->xinwen->add_data($data);
            redirect('admin/Ask/index');
        }
        $this->load->view('admin/add_news.html');
    }

    public function del(){
        $id=$this->uri->segment(4);
        $this->xinwen->del_data($id);
        redirect('admin/News/xinwen');
    }

    public function edit(){
        $id=$this->uri->segment(4);
        if($_POST){
            $data=$this->input->post();
            $data['savetime']=time();
            $this->xinwen->save_data($data,$id);
            redirect('admin/News/xinwen');
        }

        $data['news']=$this->xinwen->get_data($id);
        $this->load->view('admin/edit_news.html',$data);
    }
}